package cate.game.res.treasureturntable;

import cate.game.db.mongo.kv.KvMongo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class TreasureTurntableSPO extends KvMongo {
    @NoteField(value = "寻宝日志")
    public Map<Byte, TreasureTurntableLog> logs;

    @Override
    public String getKeyPrefix() {
        return KvMongo.KEY_TREASURE_TURNTABLE;
    }

    @Override
    public void initialize() {
        if (logs == null) {
            logs = new HashMap<>();
        }
    }

    @JsonIgnore
    public synchronized void addLog(byte turntableType, TreasureTurntableLogDetail logDetail, int maxNum) {
        TreasureTurntableLog log = getLog(turntableType);
        log.addLog(logDetail, maxNum);
    }

    public TreasureTurntableLog getLog(byte turntableType) {
        return logs.computeIfAbsent(turntableType, k -> {
            TreasureTurntableLog newLog = new TreasureTurntableLog();
            newLog.initialize();
            return newLog;
        });
    }
}
